var common = require("../../utils/common.js");
//index.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    urls:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     console.log('进入了load')
     //获取发起人token值
     console.log(options)
     this.getUserInfo(options);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log('进入了show')
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    app.globalData.isGoBack = true;
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  
  // },

  getUserInfo: function (options){
    var that = this;
    common.ajaxPost(
      'portal/wlpUsers/queryUserInfo.action', {
        xcxOpenId: app.globalData.xcxOpenId,
        bid: app.globalData.bid,
        userType:2
      },
      function (res) {
        if (res && res["result"]) {
          console.log(res)
          app.globalData.userInfo=res.userInfo;
          that.getToken(options);
        }
      }
    ) 
  },
  getToken: function (options){
    var that = this;
    console.log(app);
    var fromUserId = app.globalData.userInfo.id;
    console.log(fromUserId)
    common.ajaxPost(
      'portal/wlpRecord/queryImToken.action', {
        id: fromUserId
      },
      function (res) {
        if (res && res["result"]) {
          var fromImToken=res.imToken;
          var fromName = app.globalData.userInfo.name;
          var fromHeadImage = app.globalData.userInfo.headImage;
          var fromUserType = app.globalData.userInfo.userType;
          var fromxcxOpenId = app.globalData.userInfo.xcxOpenId;
          var fromId = app.globalData.userInfo.id;
          var toName=options.name;
          var toId = (options.id);
          var toHeadImage = options.headimage;
          var toUserType = options.usertype;
          var bid=app.globalData.bid;
          console.log(fromImToken)
          console.log(fromName)
          console.log(fromHeadImage)
          console.log(fromUserType)
          console.log(fromxcxOpenId)
          console.log(fromId)
          console.log(toName)
          console.log(toHeadImage)
          console.log(toUserType)
        // var urls = "https://xnzx.diandianja.com/Webim/demoIM_wlp.html"
           var urls = "https://px.diandianja.com/Webim/demoIM_wlp.html?fromName="+encodeURI(fromName)+"&fromHeadImage="+fromHeadImage+"&fromUserType="+fromUserType+"&fromxcxOpenId="+fromxcxOpenId+"&toName="+encodeURI(toName)+"&toId="+toId+"&toHeadImage="+toHeadImage+"&toUserType="+toUserType+"&isXcx=1&bid="+bid+"&fromId="+fromId+"&fromImToken="+fromImToken
           console.log(urls)
          that.changeUrl(urls)
        }
      }
    ) 
  },
  changeUrl: function (urls){
    console.log("changeUrl成功")
    var that=this;
    that.setData({
      urls: urls
    })
    console.log(urls)
  }
})
